//
//  JReaderSDKManager.m
//  JReaderSDK
//
//  Created by linziyuan on 2017/7/17.
//  Copyright © 2017年 creative. All rights reserved.
//

#import "JReaderSDKManager.h"
#import "ConstDefine.h"

@implementation JReaderSDKManager

+ (void)openBookWitBookId:(NSInteger)bookid bookName:(NSString *)bookName bookSourcePath:(NSString *)sourcePath currentVC:(UIViewController *)currentVC pageChanged:(void(^) (NSInteger currentPage))pageChanged Success:(void(^)())success failure:(void(^) ())failure {
    if (!currentVC) {
        return;
    }
    if (!sourcePath) {
        return;
    }
    [JReaderSDKManager supportFileSetUp];
    if (pageChanged) {
        [DataProcessing shareSingle].pageChangedBlock = pageChanged;
    }
    [DataProcessing do_Main_quick:^{
        BOOL isStatus = YES;
        if ([DataProcessing shareSingle].deviceType == DevicesTypes_iPhone) {
            isStatus = NO;
        }
        [DataProcessing shareSingle].isStatusHidden = isStatus;
        [[UIApplication sharedApplication] setStatusBarHidden:isStatus];
        [DataProcessing shareSingle].isOutPath = YES;
        [DataProcessing shareSingle].outPath = sourcePath;
        TABLE_BOOKS *tbBook = [[TABLE_BOOKS alloc] init];
        tbBook.bookId = bookid;
        tbBook.name_zh = bookName;
        tbBook.name_en = bookName;
        tbBook.readSource = ReadSource_JR;
        tbBook.originalId = bookid;
        [RootViewController outEnterToReadBookWithTbBook:tbBook currentVC:currentVC success:success failure:failure];
    }];
}

+ (void)readerGotoPage:(NSInteger)toPage Success:(void(^)())success failure:(void(^) ())failure {
   
    if ([ReadBookVOrH_VC currentReadInstance]) {
        if (toPage <0 || toPage >= [ReadBookVOrH_VC currentReadInstance].pagesArr.count) {
            if (failure) {
                NSLog(@"--页码产出范围");
                failure();
            }
        }else {
            [[ReadBookVOrH_VC currentReadInstance] gotToPageIndex:toPage];
            if (success) {
                success();
            }
        }
    }else {
        if (failure) {
            NSLog(@"--阅读器不存在");
            failure();
        }
    }
}

+ (void)hideReaderViews {
    if ([ReadBookVOrH_VC currentReadInstance]) {
        [ReadBookVOrH_VC currentReadInstance].view.hidden = YES;
    }
}

+ (void)showReaderViews {
    if ([ReadBookVOrH_VC currentReadInstance]) {
        [ReadBookVOrH_VC currentReadInstance].view.hidden = NO;
    }
}

+ (void)readerClickSoundBtn {
    if ([ReadBookVOrH_VC currentReadInstance]) {
        [[ReadBookVOrH_VC currentReadInstance] msgTo_menthed:@"clicked_soundBtn" refs:@[] needReturnValue:NO];
    }
}

+ (void)supportFileSetUp {
    [DataProcessing shareSingle].wordsPeitu_url = @"https://wawa-qin.b0.upaiyun.com/ft_image";
    [DataProcessing shareSingle].wordsDuyin_url = @"https://wawa-qin.b0.upaiyun.com/tushu";
    [DataProcessing shareSingle].quiz_url = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].book_cover_img_url = @"https://wawaqinpic.b0.upaiyun.com";
    [DataProcessing shareSingle].bookshelf_icon_img_url = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].bookshelf_icon_img_url = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].book_zip_file_url = @"http://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].support_file_url = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].avatar_host = @"https://img-joyreader.wawayaya.com/";
    [DataProcessing shareSingle].talk_file_url = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].advert_img_url = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].audio_file_url = @"https://hzjaikan.b0.upaiyun.com";
    [DataProcessing shareSingle].word_dict_url = @"https://hzjaikan.b0.upaiyun.com/word/";
    [DataProcessing shareSingle].flowBook_host = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].freval_data_host = @"https://wawa-qin.b0.upaiyun.com";
    [DataProcessing shareSingle].quiz_common_scripts_host = @"https://wawa-qin.b0.upaiyun.com";
}

@end
